package com.ljtxxhwj.myblob.service.impl;

import com.ljtxxhwj.myblob.entity.FavoriteFolder;
import com.ljtxxhwj.myblob.mapper.FavoriteFolderMapper;
import com.ljtxxhwj.myblob.service.FavoriteFolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class FavoriteFolderServiceImpl implements FavoriteFolderService {

    private final FavoriteFolderMapper favoriteFolderMapper;

    @Autowired
    public FavoriteFolderServiceImpl(FavoriteFolderMapper favoriteFolderMapper) {
        this.favoriteFolderMapper = favoriteFolderMapper;
    }

    @Override
    public FavoriteFolder getFavoriteFolderByName(String favoriteFolderName) {
        return favoriteFolderMapper.selectFavoriteFolderByName(favoriteFolderName);
    }

    @Override
    public void addFavoriteFolder(FavoriteFolder favoriteFolder) {
        Timestamp folderTime = new Timestamp(new java.util.Date().getTime());

        favoriteFolder.setFavoriteFolderDate(folderTime);
        favoriteFolderMapper.insertFavoriteFolder(favoriteFolder);
    }

    @Override
    public void updateFavoriteFolderName(Integer favoriteFolderId, String newFavoriteFolderName) {
        favoriteFolderMapper.updateFavoriteFolderName(favoriteFolderId, newFavoriteFolderName);
    }

    @Override
    public void deleteFavoriteFolderById(Integer favoriteFolderId) {
        favoriteFolderMapper.deleteFavoriteFolderById(favoriteFolderId);
    }

    @Override
    public List<FavoriteFolder> getAllFavoriteFolders() {
        System.out.println("favoriteFolderMapper = " + favoriteFolderMapper.selectAllFavoriteFolders());
        return favoriteFolderMapper.selectAllFavoriteFolders();
    }
}